<template  xmlns="http://www.w3.org/1999/html">
  <div class="app-container">
    <!-- 查询条件区域-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="点位名称" prop="position_name">
        <el-input v-model="queryParams.position_name" placeholder="请输入点位名称" clearable @keyup.enter.native="handleQuery"
          size="small" />
      </el-form-item>
      <el-form-item label="点位编码" prop="position_num">
        <el-input v-model="queryParams.position_num" placeholder="请输入点位编码" clearable @keyup.enter.native="handleQuery"
          size="small" />
      </el-form-item>
      <el-form-item>
        <el-button style="margin-left:20px;" type="primary" icon="el-icon-search" size="small"
          @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!--  数据列表区域-->
    <el-table v-loading="loading" :data="patrolpointList" @selection-change="handleSelectionChange"
      :cell-style="{ borderColor: 'rgb(1 5 43)' }" :header-cell-style="{ borderColor: 'rgb(1 5 43)' }">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="点位名称" align="center" prop="position_name" width="120" />
      <el-table-column label="池子编号" align="center" width="120" prop="pond_num" :show-overflow-tooltip="true"  />
      <el-table-column label="点位编码" align="center" prop="position_num" width="100" />
      <el-table-column label="巡检点到起点距离(m)" align="center" prop="position_dist" width="160" />
      <el-table-column label="创建时间" align="center" prop="creater_time">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.creater_time) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="340" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
          v-hasPermi="['nssc:patrolpoint:edit']">点距/角度设置</el-button>
        <el-button size="mini" type="text" icon="el-icon-edit" @click="xjdUpdate(scope.row)"
          v-hasPermi="['nssc:patrolpoint:edit']">巡检点设置</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="czbhUpdate(scope.row)"
          v-hasPermi="['nssc:patrolpoint:edit']">池子编号设置</el-button>
        <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
          v-hasPermi="['nssc:patrolpoint:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--列表分页区域-->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" style="background:rgb(1 5 43);" />

    <!-- 巡检点配置对话框 -->
    <el-dialog :title="title1" :visible.sync="open1" width="650px" append-to-body>
      <el-form ref="form1" :model="form1" label-width="100px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="巡检点编号" prop="position_num">
              <el-input v-model="form1.position_num" clearable placeholder="请输入或置空巡检点编号" style="width: 200px" />
              <div style="color:red;font-size: 12px">
                提醒！非巡检点置空编号即可
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm1">确 定</el-button>
        <el-button @click="cancel1">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 池子编号配置对话框 -->
    <el-dialog :title="title2" :visible.sync="open2" width="650px" append-to-body>
      <el-form ref="form2" :model="form2" label-width="100px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="池子编号" prop="pond_num">
              <el-input v-model="form2.pond_num" clearable placeholder="请输入池子编号" style="width: 200px" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm2">确 定</el-button>
        <el-button @click="cancel2">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 点距/角度设置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="650px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="95px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="1号摄像头水平角度" prop="x_point1">
              <el-input class="inpSize" v-model="form.x_point1" placeholder="请输入水平角度(0-3550)" style="width: 200px" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="1号摄像头垂直角度" prop="y_point1">
              <el-input v-model="form.y_point1" id="cz1Input" placeholder="请输入垂直角度(0-900)" style="width: 200px" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="点位距始点距离" prop="position_dist">
              <el-input v-model="form.position_dist" placeholder="请输入点位到始点距离" style="width: 200px" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  delPatrolPoint,
  getPatrolPoint,
  listPatrolPoint,
  updatePatrolPoint,
  updatePatrolPointNum, updatePatrolPondNum
} from "@/api/nssc/patrolpoint/patrolpoint";
import "@/assets/styles/robt-bg.css";

export default {
  dicts: ['map_type'],
  data() {
    return {
      camera_type1: undefined,
      // 是否显示弹出层
      open: false,
      open1: false,
      open2: false,
      // 弹出层标题
      title: "",
      title1: "",
      title2: "",
      // 总条数
      total: 0,
      // 巡检点表格数据
      patrolpointList: [],
      // 遮罩层
      loading: true,
      // 非多个禁用
      multiple: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 7,
        position_name: undefined,
        robot_name: undefined,
        position_dist: undefined,
        camera_type: undefined
      },
      // 表单参数
      form: {
        q_x_point: 0
      },
      // 表单参数
      form1: {
      },
      form2:{
      },
      // 表单校验
      rules: {
        position_dist: [
          { required: true, message: "距离起点距离不能为空", trigger: "blur" }
        ]
      }
    }
  },
  created() {
    this.getList(); //地图列表
  },
  methods: {
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids
      getPatrolPoint(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "点距/角度设置";
      });
    },
    /** 巡检点配置操作 */
    xjdUpdate(row) {
      const id = row.id || this.ids
      getPatrolPoint(id).then(response => {
        this.form1 = response.data;
        this.open1 = true;
        this.title1 = "巡检点设置";
      });
    }, /** 池子配置操作 */
    czbhUpdate(row) {
      const id = row.id || this.ids
      getPatrolPoint(id).then(response => {
        this.form2 = response.data;
        this.open2 = true;
        this.title2 = "池子编号设置";
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    cancel1() {
      this.open1 = false;
      this.reset1();
    },
    // 表单重置
    reset1() {
      this.form1 = {
        position_num: undefined
      };
      this.resetForm("form1");
    },
    // 取消按钮
    cancel2() {
      this.open2 = false;
      this.reset2();
    },
    // 表单重置
    reset2() {
      this.form2 = {
        pond_num: undefined
      };
      this.resetForm("form2");
    },
    /** 查询巡检点列表 */
    getList() {
      this.loading = true;
      listPatrolPoint(this.queryParams).then(response => {
        this.patrolpointList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    }, //表格相同数据列合并
    flitterData4() {
      let spanOneArr = []
      let concatOne = 0
      this.patrolpointList.forEach((item, index) => {//循环后端查询出来的数据(patrolpointList)
        if (index === 0) {
          spanOneArr.push(1)
        } else {
          //name 修改
          if (item.robot_name === this.patrolpointList[index - 1].robot_name) { //第一列需合并相同内容的字段
            spanOneArr[concatOne] += 1
            spanOneArr.push(0)
          } else {
            spanOneArr.push(1)
            concatOne = index
          }
        }
      })
      return {
        one: spanOneArr,
      }
    },// 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.position_num = null;
      this.queryParams.position_name = null;
      this.queryParams.robot_config_id = null;
      this.queryParams.robot_name = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除选中的数据项？').then(function () {
        return delPatrolPoint(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updatePatrolPoint(this.form).then(response => {
              this.$modal.msgSuccess("设置成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 提交按钮 */
    submitForm1: function () {
      this.$refs["form1"].validate(valid => {
        if (valid) {
          if (this.form1.id != undefined) {
            updatePatrolPointNum(this.form1).then(response => {
              this.$modal.msgSuccess("设置成功");
              this.open1 = false;
              this.getList();
            });
          }
        }
      });
    },
    submitForm2: function () {
      this.$refs["form2"].validate(valid => {
        if (valid) {
          if (this.form2.id != undefined) {
            updatePatrolPondNum(this.form2).then(response => {
              this.$modal.msgSuccess("设置成功");
              this.open2 = false;
              this.getList();
            });
          }
        }
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  width: 100%;
  height: calc(100vh - 40px);
  // background: #081a46;
  //padding-left:0;
}

.el-input--small .el-input__inner {
  border-color: #195083;
  height: 32px;
  line-height: 32px;
  background-color: #0e2356;
}

::v-deep .el-input--medium .el-input__inner {
  font-size: 12px !important;
}
</style>
